package qe.spider;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.time.Duration;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");

        String chromePath = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
        System.setProperty("webdriver.edge.bin", chromePath);
        String driverPath = "d:\\msedgedriver.exe";
        System.setProperty("webdriver.edge.driver", driverPath);

        EdgeOptions options = new EdgeOptions();
        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));

        WebDriver web = new EdgeDriver(options);
        String url = "https://www.iwencai.com/unifiedwap/result?w=" + "000919,603949,000705" + "%E6%9C%80%E8%BF%915%E4%B8%AA%E4%BA%A4%E6%98%93%E6%97%A5%E6%9C%89%E8%BF%87%E6%B6%A8%E5%81%9C%E6%88%96%E8%B7%8C%E5%81%9C%E5%90%97&querytype=stock";

        web.get(url);
        web.getTitle();
        String ret = web.getPageSource();

        web.manage().timeouts().implicitlyWait(Duration.ofMillis(500));

        WebElement textBox = web.findElement(By.xpath("/html/body/div[1]/div[1]/div/div[2]/div[1]/div[1]/div/div[1]/div[1]/div/textarea"));
        WebElement submitButton = web.findElement(By.xpath("/html/body/div[1]/div[1]/div/div[2]/div[1]/div[1]/div/div[1]/div[2]/i"));
        textBox.clear();
        textBox.sendKeys("昨天涨跌停的股票");
        submitButton.click();

        web.quit();
    }
}